﻿$(document).ready(function() {
       
        $('#datepicker').datepicker({ dateFormat: "yy-mm-dd" });
       
    $('#submit').click(function(event) {
        $('#result').html('<center><b>...Mohon Tunggu...</b><br>...Kami Sedang Mencari Tiket Pesawat Untuk Anda...<br><br><img src="loading.gif"></center>');
        var FormData = $('#FormTiket').serialize();
        event.preventDefault();
        $.ajax({
            type : "GET",
            url:'http://cari.ibetiket.com/tiket.php',
            data: FormData,
            cache: false,
            dataType: "jsonp",
            success:function(data){
                    if(data==''){
                        $('#result').empty();
                        $('#result').html('Maaf, data tidak ada untuk rute ini.');
                    }else{
                        $('#result').empty();
                        var div = $("#result");
div.append("<center>");
div.append("<table style='width:800px;border:1px solid #0099CC;cellspacing:0px;cellpadding:0px;-moz-border-radius: 5px 5px 5px 5px;-webkit-border-radius: 5px 5px 5px 5px;border-radius: 5px 5px 5px 5px;'>");              
div.append("<tr style='valign:middle;'>");
div.append("<th colspan='3' style='width:240px;height:80px;background-color:#0099CC;font-weight:bold;color:#FFFFFF;text-align:center;'><div style='margin-top:35px;'>PESAWAT</div></th>");
div.append("<th colspan='2' style='width:100px;height:80px;background-color:#0099CC;font-weight:bold;color:#FFFFFF;text-align:center;'><div style='margin-top:35px;'>PERGI     -     TIBA</div></th>");
div.append("<th style='width:100px;height:80px;background-color:#0099CC;font-weight:bold;color:#FFFFFF;text-align:center;'><div style='margin-top:35px;'>DURASI FLIGHT</div></th>");
div.append("<th style='width:170px;height:80px;background-color:#0099CC;font-weight:bold;color:#FFFFFF;text-align:center;'><div style='margin-top:35px;'>HARGA TIKET</div></th>");
div.append("<th style='width:190px;height:80px;background-color:#0099CC;font-weight:bold;color:#FFFFFF;text-align:center;'><div style='margin-top:35px;'>ORDER TIKET</div></th>");
div.append("</tr>");
                        for(var i=0; i<data[0].departures.result.length;i++){         
div.append("<tr>");
div.append("<td style='width:80px;height:20px;color:#000066;text-align:center;border-left:1px dashed #0044BB;border-bottom:1px dashed #0044BB;'>"+data[0].departures.result[i].flight_id+"</td>");
div.append("<td style='width:80px;height:20px;color:#000066;text-align:center;border-bottom:1px dashed #0044BB;'><img style='width:40px;height:40px;-moz-border-radius: 8px 8px 8px 8px;-webkit-border-radius: 8px 8px 8px 8px;border-radius: 8px 8px 8px 8px;border:1px solid #B1B1B1;margin-top:10px;margin-bottom:-20px;' src='"+data[0].departures.result[i].image+"'></td>");
div.append("<td style='width:80px;height:20px;color:#000066;text-align:center;border-right:1px dashed #0044BB;border-bottom:1px dashed #0044BB;'>"+data[0].departures.result[i].flight_number+"</td>");
div.append("<td style='width:70px;height:20px;color:#000066;text-align:center;border-right:1px dashed #0044BB;border-bottom:1px dashed #0044BB;'>"+data[0].departures.result[i].simple_departure_time+"</td>");
div.append("<td style='width:70px;height:20px;color:#000066;text-align:center;border-right:1px dashed #0044BB;border-bottom:1px dashed #0044BB;'>"+data[0].departures.result[i].simple_arrival_time+"</td>");
div.append("<td style='width:110px;height:20px;color:#000066;text-align:center;border-right:1px dashed #0044BB;border-bottom:1px dashed #0044BB;'>"+data[0].departures.result[i].duration+"</td>");
div.append("<td style='width:120px;height:20px;color:#000066;text-align:center;border-right:1px dashed #0044BB;border-bottom:1px dashed #0044BB;'>Rp."+data[0].departures.result[i].price_value+"<br>per orang</td>");
div.append("<td style='width:190px;height:50px;color:#99CC;text-align:center;border-right:1px dashed #0044BB;border-bottom:1px dashed #0044BB;'><a target='new' href=order.php?flightid="+data[0].departures.result[i].flight_id+"&pesawat="+data[0].departures.result[i].airlines_name+"&harga="+data[0].departures.result[i].price_adult+"&nomorflight="+data[0].departures.result[i].flight_number+"&tanggal="+data[0].departures.result[i].date+">PESAN TIKET</a></td>");
div.append("</tr>");
                        }  
div.append("</table>");
div.append("</center>");
                    }
                }
        })
    });
});